/*
 * PGConnection.java
 *
 * Created on 14. August 2007, 10:19
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.googlecode.oskis.library.db;
import java.sql.*;

/**
 * Klasse zum Zugriff auf Postgresql Datenbanken
 * @author thomas
 */
public class PGConnection extends DBConnection {
        
    /**
     * 
     * @return
     */
    protected Connection createConnection() {
        Connection c;
        if (user==null || passwd==null || ip==null
            || database==null) {
            return(null);
        }
        try {
            Class.forName("org.postgresql.Driver");
            c = DriverManager.getConnection("jdbc:postgresql://"+ip+"/"+database,user,passwd);
            connected=true;
        } catch (Exception e) {
            System.err.println(e);
            c=null;
            connected=false;
            connectionError=e.toString();
        }
        return(c);
    }
    
    
    /** Creates a new instance of PGConnection */
    public PGConnection() {
        readProperties();
        this.db=createConnection();
    }
    public PGConnection(String database) {
        readProperties();
        setDatabase(database);
        this.db=createConnection();
    }
    public PGConnection(String ip,String database,String user,String passwd) {
        setDatabase(database);
        setIP(ip);
        setUser(user);
        setPasswd(passwd);
        this.db=createConnection();
    }
}
